package com.codebyorder.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Base64;

public class ImgToByte {
    public static String ImageToBase64(MultipartFile file) {
        byte[] data = null;
        try {
            data = new byte[file.getInputStream().available()];
            file.getInputStream().read(data);
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 返回Base64编码过的字节数组字符串

        return Base64.getEncoder().encodeToString(data);
    }

}
